package org.example.HttpClient.impl;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.example.HttpClient.HttpInterface.Functional.HttpCatchFunctional;
import org.example.HttpClient.HttpInterface.Functional.HttpFinallyFunctional;
import org.example.HttpClient.HttpInterface.Functional.HttpThenFunctional;
import org.example.HttpClient.HttpInterface.HttpController;

public abstract class JAxiosEventProcessing extends JAxiosConfig{

    @Override
    public HttpController Catch(HttpCatchFunctional httpCatchFunctional) {
        axiosConfig.setCatchFunctional(httpCatchFunctional);
        return this;
    }

    @Override
    public HttpController Finally(HttpFinallyFunctional httpFinallyFunctional) {
        axiosConfig.setFinallyFunctional(httpFinallyFunctional);

        return this;
    }

    @Override
    public HttpController Then(HttpThenFunctional httpThenFunctional) {
        axiosConfig.setThenFunctional(httpThenFunctional);
        return this;
    }

    public void RunCatchFunctional(CloseableHttpResponse response){
        HttpCatchFunctional CatchFunctional = axiosConfig.getCatchFunctional();
        if (CatchFunctional != null) {
            CatchFunctional.Catch(response);
        }
    }
    public void RunFinallyFunctional(){
        HttpFinallyFunctional FinallyFunctional = axiosConfig.getFinallyFunctional();
        if (FinallyFunctional!= null) {
            FinallyFunctional.Finally();
        }
    }
    public void RunThenFunctional(CloseableHttpResponse e){
        HttpThenFunctional ThenFunctional = axiosConfig.getThenFunctional();

        if (ThenFunctional!= null) {
            ThenFunctional.Then(e);
        }
    }

}
